package com.ruoyi.web.controller.mall;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mall.domain.BizClassify;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.domain.BizWares;
import com.ruoyi.mall.service.IBizWaresService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品列表Controller
 * 
 * @author WeiHuan.Li
 * @date 2024-04-29
 */
@RestController
@RequestMapping("/mall/wares")
public class BizWaresController extends BaseController
{
    @Autowired
    private IBizWaresService bizWaresService;

    /**
     * 查询商品列表列表
     */
    @PreAuthorize("@ss.hasPermi('mall:wares:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizWares bizWares)
    {
        startPage();
        List<BizWares> list = bizWaresService.selectBizWaresList(bizWares);
        return getDataTable(list);
    }

    /**
     * 导出商品列表列表
     */
    @PreAuthorize("@ss.hasPermi('mall:wares:export')")
    @Log(title = "商品列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizWares bizWares)
    {
        List<BizWares> list = bizWaresService.selectBizWaresList(bizWares);
        ExcelUtil<BizWares> util = new ExcelUtil<BizWares>(BizWares.class);
        util.exportExcel(response, list, "商品列表数据");
    }

    /**
     * 获取商品列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:wares:query')")
    @GetMapping(value = "/{waresId}")
    public AjaxResult getInfo(@PathVariable("waresId") Long waresId)
    {
        return success(bizWaresService.selectBizWaresByWaresId(waresId));
    }

    /**
     * 新增商品列表
     */
    @PreAuthorize("@ss.hasPermi('mall:wares:add')")
    @Log(title = "商品列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizWares bizWares)
    {
        return toAjax(bizWaresService.insertBizWares(bizWares));
    }

    /**
     * 修改商品列表
     */
    @PreAuthorize("@ss.hasPermi('mall:wares:edit')")
    @Log(title = "商品列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizWares bizWares)
    {
        return toAjax(bizWaresService.updateBizWares(bizWares));
    }

    /**
     * 删除商品列表
     */
    @PreAuthorize("@ss.hasPermi('mall:wares:remove')")
    @Log(title = "商品列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{waresIds}")
    public AjaxResult remove(@PathVariable Long[] waresIds)
    {
        return toAjax(bizWaresService.deleteBizWaresByWaresIds(waresIds));
    }

    /**
     * 禁用-启用
     * @param bizWares
     * @return
     */
    @PreAuthorize("@ss.hasPermi('mall:classify:edit')")
    @Log(title = "启用-禁用", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody BizWares bizWares)
    {
        bizWares.setUpdateBy(getUsername());
        return toAjax(bizWaresService.updateBizWares(bizWares));
    }
}
